home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
IRIX 6.2 Applications 1996 May
/
SGI IRIX 6.2 Applications 1996 May.iso
/
dist
/
impr_dev.idb
/
usr
/
impressario
/
src
/
libprintui
/
RootWin.c.z
/
RootWin.c
Wrap
C/C++ Source or Header
|
1996-05-06
|
13KB
|
411 lines
/**************************************************************************
*
* Copyright (c) 1993 Silicon Graphics, Inc.
* All Rights Reserved
*
* THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF SGI
*
* The copyright notice above does not evidence any actual of intended
* publication of such source code, and is an unpublished work by Silicon
* Graphics, Inc. This material contains CONFIDENTIAL INFORMATION that is
* the property of Silicon Graphics, Inc. Any use, duplication or
* disclosure not specifically authorized by Silicon Graphics is strictly
* prohibited.
*
* RESTRICTED RIGHTS LEGEND:
*
* Use, duplication or disclosure by the Government is subject to
* restrictions as set forth in subdivision (c)(1)(ii) of the Rights in
* Technical Data and Computer Software clause at DFARS 52.227-7013,
* and/or in similar or successor clauses in the FAR, DOD or NASA FAR
* Supplement. Unpublished - rights reserved under the Copyright Laws of
* the United States. Contractor is SILICON GRAPHICS, INC., 2011 N.
* Shoreline Blvd., Mountain View, CA 94039-7311
**************************************************************************
*
* File: RootWin.c
*
* Description: RootWin is a widget that acts as a widget for the root
* or any other X window. This allows one to use Xt functions on the
* window. One use of this widget is to call XtAddEventHandler on the
* root window to get such events as MapNotify to tell us when something
* maps on the root window.
*
* CAVEATS:
* 1. If a window other than the root window is specified, DO NOT
* unrealize the widget. Unrealizing the widget in this case
* will destroy the window. The root window is immune to this
* behavior. It is permissable to destroy the widget.
*
* 2. Be aware that only one instance of this widget is created
* per window per application. After the initial instance of
* this widget is created for a window all subsequent calls
* to _PuiCreateRootWin will return the original widget ID.
* Therefore, if you add an event handler you may get called
* unexpectedly; verify your events.
*
* NOTES:
* 1. The widget must be managed. Map events will not be
* generated because the mapped_when_managed core resource
* is explicitly set to False.
*
* 2. If a window is not specified (via the PuiNwindow resource),
* the root window is assumed. To change the window after
* widget creation, you must unrealize the widget, set the
* PuiNwindow resource and the realize the widget.
*
**************************************************************************/
#ident "$Revision: 1.3 $"
#include <stdio.h>
#include <unistd.h>
#include <msgs/uxsgiimpr.h>
#include <X11/IntrinsicP.h>
#include <X11/StringDefs.h>
#include "RootWinP.h"
/* Resource offset macro */
#define offset(field) XtOffsetOf(PuiRootWinRec, field)
/* Widget methods */
static void Initialize(Widget, Widget, ArgList, Cardinal*);
static Boolean SetValues(Widget, Widget, Widget, ArgList, Cardinal*);
static void Realize(Widget, XtValueMask*, XSetWindowAttributes*);
static void Destroy(Widget);
/* Widget resources */
static XtResource resources[] = {
/* Window for which we are a widget */
{
PuiNwindow, PuiCWindow, XtRWindow, sizeof(Window),
offset(rootWin.res_window), XtRImmediate, (XtPointer)NULL
},
};
/* Class record initialization */
PuiRootWinClassRec puiRootWinClassRec = {
{ /* Core class fields */
/* superclass */ (WidgetClass)&coreClassRec,
/* class_name */ "PuiRootWin",
/* widget_size */ sizeof(PuiRootWinRec),
/* class_initialize */ NULL,
/* class_part_initialize */ NULL,
/* class_inited */ False,
/* initialize */ Initialize,
/* initialize_hook */ NULL,
/* realize */ Realize,
/* actions */ NULL,
/* num_actions */ 0,
/* resources */ resources,
/* num_resources */ XtNumber(resources),
/* xrm_class */ NULLQUARK,
/* compress_motion */ True,
/* compress_exposure */ True,
/* compress_enterleave */ True,
/* visible_interest */ False,
/* destroy */ Destroy,
/* resize */ XtInheritResize,
/* expose */ XtInheritExpose,
/* set_values */ SetValues,
/* set_values_hook */ NULL,
/* set_values_almost */ XtInheritSetValuesAlmost,
/* get_values_hook */ NULL,
/* accept_focus */ XtInheritAcceptFocus,
/* version */ XtVersion,
/* callback_private */ NULL,
/* tm_table */ NULL,
/* query_geometry */ XtInheritQueryGeometry,
/* display_accelerator */ XtInheritDisplayAccelerator,
/* extension */ NULL,
},
{ /* PuiRootWin class fields */
/* dummy */ NULL,
}
};
WidgetClass puiRootWinWidgetClass = (WidgetClass)&puiRootWinClassRec;
/* Undocumented Xt external functions */
/* XtRegisterWindow hashes a window with a widget so that event arriving
on a window can be sent to the appropriate widget. XtUnregisterWindow
destroys the hashing.
*/
extern void _XtRegisterWindow(Window, Widget);
extern void _XtUnregisterWindow(Window, Widget);
/* Local functions */
static void SetCoreMembers(Widget w);
/*
=======================================================================
STANDARD WIDGET METHODS
=======================================================================
*/
/**************************************************************************
*
* Function: Initialize
*
* Description: Widget initialization method.
*
* Parameters:
* treq (I) - widget as set by arg list, resource database and defaults
* tnew (I) - new widget
* args (I) - argument list in Va creation
* num_args (I) - number of arguments
*
* Return: none
*
**************************************************************************/
static void Initialize(Widget treq, Widget tnew, ArgList args,
Cardinal *num_args)
{
register PuiRootWinPart *rwp = &((PuiRootWinWidget)tnew)->rootWin;
/*
* Set certain key core member fields
*/
SetCoreMembers(tnew);
/*
* We need to set the window in the initialize routine because we need
* XtWindowToWidget to work as soon as the widget is created. That way
* we prevent multiple of these widgets being created for the same
* window. Setting the window here does not hurt anything. It only
* means that Xt will think we are realized and not call our realize
* routine. That is OK too since the only thing the realize routine does
* that we don't do here is setting event masks with select input. Since
* Xt thinks we're realized, it will call select input anyway if we add
* an event handler.
*
* Determine whether a window has been specified or if we should
* default to the root window. We simply set our core window field
* to the existing window's ID and we now have a widget for the
* window.
*/
if (rwp->res_window)
XtWindow(tnew) = rwp->res_window;
else
XtWindow(tnew) = RootWindowOfScreen(XtScreen(tnew));
_XtRegisterWindow(XtWindow(tnew), tnew);
}
/**************************************************************************
*
* Function: Realize
*
* Description: The widget realize method.
*
* Parameters: Standard Realize procedure parameters
*
* Return: none
*
**************************************************************************/
static void Realize(Widget w, XtValueMask *valueMask,
XSetWindowAttributes *attributes)
{
register PuiRootWinPart *rwp = &((PuiRootWinWidget)w)->rootWin;
XWindowAttributes xwa;
/*
* Determine whether a window has been specified or if we should
* default to the root window. We simply set our core window field
* to the existing window's ID and we now have a widget for the
* window.
*/
if (rwp->res_window)
XtWindow(w) = rwp->res_window;
else
XtWindow(w) = RootWindowOfScreen(XtScreen(w));
/*
* Get the window's attributes for our event mask and for setting
* our core memeber fields.
*/
XGetWindowAttributes(XtDisplay(w), XtWindow(w), &xwa);
/*
* We need to explicitly set the event mask on the window
* to make sure that we get the events. This is because no
* new window has been created. Normally the event mask is
* set on window creation in the event mask field of the window
* attributes.
*/
XSelectInput(XtDisplay(w), XtWindow(w), xwa.your_event_mask |
attributes->event_mask);
}
/**************************************************************************
*
* Function: Destroy
*
* Description: Called on widget destruction. We set the widget window
* ID to None so that the window does not get destroyed.
*
* Parameters:
* w (I) - this widget
*
* Return: none
*
**************************************************************************/
static void Destroy(Widget w)
{
_XtUnregisterWindow(XtWindow(w), w);
XtWindow(w) = None;
}
/**************************************************************************
*
* Function: SetValues
*
* Description: Handles the setting of resource values by the XtSetValues
* Xt function.
*
* Parameters:
* cur (I) - current settings of widget variables
* req (I) - requested values of widget variables not processed
* by superclass.
* new (I) - new widget values already processed by superclass
* args (I) - arguments to SetValues function
* num_args (I) - number of arguments in args
*
* Return: True if XClearArea is to be called and expose event generated,
* Flase if no redisplay required.
*
**************************************************************************/
/* ARGSUSED */
static Boolean SetValues(Widget cur, Widget req, Widget new,
ArgList args, Cardinal *num_args)
{
register PuiRootWinPart *crwp = &((PuiRootWinWidget)cur)->rootWin;
register PuiRootWinPart *nrwp = &((PuiRootWinWidget)new)->rootWin;
/* Window to monitor */
if ((crwp->res_window != nrwp->res_window) && XtIsRealized(new)) {
nrwp->res_window = crwp->res_window;
XtWarning(gettxt(_SGI_LIBPRINTUI_WINCHANGE,
"PuiRootWin - cannot change PuiNwindow after widget realization"));
}
return False;
}
/*
==========================================================================
LOCAL FUNCTIONS
==========================================================================
*/
/**************************************************************************
*
* Function: SetCoreMembers
*
* Description: Sets a basic set of core member fields so that GetValues
* on these fields return something defined. We set dimension fields
* to 0 so that there is no visible layout effect on the parent.
*
* Parameters:
* w (I) - this widget
*
* Return: none
*
**************************************************************************/
static void SetCoreMembers(register Widget w)
{
w->core.x = 0;
w->core.y = 0;
w->core.width = 0;
w->core.height = 0;
w->core.border_width = 0;
w->core.mapped_when_managed = False;
}
/*
==========================================================================
PUBLIC AND CONVENIENCE FUNCTIONS
==========================================================================
*/
/**************************************************************************
*
* Function: _PuiCreateRootWin
*
* Description: Creates a managed RootWin widget if one does not already
* exist for the specified window. Note that this function ensures
* that there is only on RootWin widget per window.
*
* Parameters:
* parent (I) - parent widget ID
* name (I) - instance name for newly created widget
* args (I) - widget resource settings
* num (I) - number of resources specified.
*
* Return: Widget ID of newly created RootWin widget.
*
**************************************************************************/
Widget _PuiCreateRootWin(Widget parent, String name, ArgList args,
Cardinal num)
{
Widget widget;
Window win = None;
ArgList aptr;
int i;
/*
* See if a window ID has been specified as a resource
*/
for (i = 0, aptr = args; i < num; i++, aptr++) {
if (strcmp(aptr->name, PuiNwindow) == 0 ||
strcmp(aptr->name, PuiCWindow) == 0)
win = aptr->value;
}
/*
* If no window specified, use the root window
*/
if (win == None)
win = RootWindowOfScreen(XtScreen(parent));
/*
* If a widget already exists for this window we must use that
* since Xt only understands one widget per window. If there is
* no widget for the window, create a RootWin widget for the window.
*/
if ((widget = XtWindowToWidget(XtDisplay(parent), win)) == NULL)
widget = XtCreateManagedWidget(name, puiRootWinWidgetClass,
parent, args, num);
return widget;
}